<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "/include/head_common.ftl">
	<#include "/include/login_trace.ftl">
	<#assign permissionSet = fm.getPermission() />
	<#assign edit= fm.hasPermission("sql:parameter:edit",permissionSet)/>
<title>SQL参数</title>
    <script type="text/javascript">
        function page(n, s) {
            $("#pageNum").val(n);
            $("#pageSize").val(s);
            $("#searchForm")[0].submit();
            return false;
        }
		function updateSort() {
			loading('正在提交，请稍等...');
			$("#listForm").submit();
		}
		function clearDescribeQuery(){
			$("#paramName").val('');
			$("#paramDescribe").val('');
			$("#searchForm")[0].submit();
		}
		function addPageParam(){
			var defineKey = $('#selectDefineKey').val().replace(/(^\s*)|(\s*$)/g, "");
			if(defineKey.length > 0){
				window.location='${rootUrl}/sql/parameter/pageParam?defineKey='+ defineKey;
			} else {
				top.$.jBox.tip("请选择添加的SQL定义", "error", {
					persistent : true,
					opacity : 0,
					timeout: 500
				});
			}
		}
    </script>
</head>
<body>
	<ul class="nav nav-tabs">
		<#if fm.hasPermission("sql:define:view",permissionSet) >
			<li><a href="${rootUrl}/sql/define/list">SQL列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:define:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/define/edit">SQL添加</a></li>
		</#if>
		<li class="active"><a href="${rootUrl}/sql/parameter/list?defineKey=${parameter.defineKey!''}">SQL参数列表</a></li>
		<#if edit >
			<li><a href="${rootUrl}/sql/parameter/edit?defineKey=${parameter.defineKey!''}">SQL参数添加</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:view",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/list">列转换器列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/edit">列转换器添加</a></li>
		</#if>
	</ul>
	<form id="searchForm" action="${rootUrl}/sql/parameter/list"
		  method="post" class="breadcrumb form-search">
		<input id="pageNum" name="pageNum" type="hidden" value="${page.pageNum}" />
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />
		<label>sql定义key：</label>
		<select name="defineKey" class="input-xlarge" id = "selectDefineKey">
			<option value="">请选择</option>
			<#list defineList as define>
				<option value="${define.defineKey}" <#if parameter.defineKey?? && define.defineKey = parameter.defineKey> selected </#if>>
					${define.defineKey}(${define.sqlDescribe})
				</option>
			</#list>
		</select>&nbsp;&nbsp;
		<label>参数名 ：</label>
		<input type="text" id = "paramName" name="paramName" maxlength="50" class="input-medium" value="${parameter.paramName!''}"/> &nbsp;
		<label>参数描述 ：</label>
		<input type="text" id="paramDescribe" name="paramDescribe" maxlength="50" class="input-medium" value="${parameter.paramDescribe!''}"/> &nbsp;
		<input class="btn btn-primary" type="submit" value="查询" />
		&nbsp;&nbsp;
		<input type="button" class="btn btn-primary" onclick="addPageParam()" value="添加分页参数" />
		&nbsp;&nbsp;
		<input type="button" class="btn btn-primary" onclick="clearDescribeQuery()" value="清除参数名和描述查询" />
		&nbsp;&nbsp;
		<#if edit>
				<input id="btnSubmit" class="btn btn-primary" type="button"
					   value="保存排序" onclick="updateSort();" />
		</#if>
	</form>
	<#include "/include/message.ftl">
	<form id="listForm" method="post" action="${rootUrl}/sql/parameter/updateSort">
		<table id="contentTable"
			   class="table table-striped table-bordered table-condensed">
			<thead>
			<tr>
				<th>sql定义key</th>
				<th>参数名</th>
				<th>参数描述</th>
				<th>参数类型</th>
				<th>是否必须</th>
				<th style="text-align: center;">排序</th>
				<th>操作</th>
				<th>默认值</th>
			</tr>
			</thead>
			<tbody>
			<#list page.list as parameter>
				<tr>
					<td><a href="${rootUrl}/sql/parameter/list?defineKey=${parameter.defineKey!''}">${parameter.defineKey!''}&nbsp;(${defineMap[parameter.defineKey!'']!''})</a></td>
					<td><a href="${rootUrl}/sql/parameter/edit?id=${parameter.id!''}">${parameter.paramName!''}</a></td>
					<td>${parameter.paramDescribe!''}</td>
					<td>${parameter.paramType!''}</td>
					<td><#if parameter.required?? && parameter.required>是<#else>否</#if></td>
					<td style="text-align: center;"><input type="hidden" name="ids" value="${parameter.id}" />
						<input name="sorts" type="text" value="${parameter.sort}"
							   style="width: 50px; margin: 0; padding: 0; text-align: center;" />
					</td>
					<td>
						<#if edit>
							<a href="${rootUrl}/sql/parameter/edit?id=${parameter.id!''}">修改</a>
							<a href="${rootUrl}/sql/parameter/delete?id=${parameter.id!''}" onclick="return confirmx('确认要删除该参数吗？', this.href)">删除</a>
						<#else>
							<a href="${rootUrl}/sql/parameter/edit?id=${parameter.id!''}">查看</a>
						</#if>
					</td>
					<td>${parameter.defaultValue!''}</td>
				</tr>
			</#list>
			</tbody>
		</table>
		<div class="pagination">
			<#assign funName = 'page' />
			<#assign ftPage = page>
			<#include "/include/page.ftl">
		</div>
	</form>
</body>
</html>